﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PokemonBattle.BattleRoom.Client;

namespace PBO.Forms.NetworkForm
{
    public partial class SelectorForm : Form
    {
        public SelectorForm()
        {
            InitializeComponent();
            this.Icon = Properties.Resources.PokemonBall;
        }

        private void LinkRoomButton_Click(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.AutoLoginUser && !string.IsNullOrEmpty(Properties.Settings.Default.UserName))
            {
                var user = new User();
                user.Name = Properties.Settings.Default.UserName;
                user.ImageKey = Properties.Settings.Default.ImageIndex;
                user.CustomDataInfo = "";
                user.CustomDataHash = "";
                Logon(user, false);
            }
            else
            {
                var logonForm = new LogonRoomForm();
                if (logonForm.ShowDialog() == DialogResult.OK)
                {
                    Logon(logonForm.UserInfo, logonForm.Advanced);
                }
            }
        }

        private void PersonalButton_Click(object sender, EventArgs e)
        {
            var perBattle = new DirectBattleForm();
            perBattle.MdiParent = this.MdiParent;
            perBattle.Show();
            PersonalButton.Enabled = false;
            perBattle.FormClosed += PersonalBattleForm_Closed;
        }

        private void PersonalBattleForm_Closed(object sender, FormClosedEventArgs e)
        {
            ((Form)sender).FormClosed -= PersonalBattleForm_Closed;
            PersonalButton.Enabled = true;
        }

        private void Logon(User user, bool advance)
        {
            Form linkForm;
            if (advance)
            {
                linkForm = new AdvanceLinkForm(user);
            }
            else
            {
                linkForm = new RoomListForm(user);
            }
            linkForm.MdiParent = this.MdiParent;
            linkForm.Show();
        }

        private void SelectorForm_Load(object sender, EventArgs e)
        {
            var motherForm = MainForm.GetInstance();
            if (motherForm.Team == null)
            {
                LinkRoomButton.Enabled = false;
                PersonalButton.Enabled = false;
            }
            //motherForm.TeamFormHided += mdiForm_TeamFormHided;
        }








    }
}
